package com.project.controller;

import com.project.bean.CutPageBean;
import com.project.bean.StudentBean;
import com.project.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("student")
public class StudentController {
    /**
     * 按页码，学生姓名，班级名，房间地址 进行分页动态模糊查询
     * 同时查询学生地址，班级名称
     */
    @Autowired
    private IStudentService service;
    @RequestMapping("findByItem")
    public CutPageBean<StudentBean> findByItem(Integer pageNo, String name, String className, String room){
        return service.findByItem(pageNo,name,className,room);
    }

    /**
     * 按id查询学生信息 房间地址，班级名称
     * @param id 学生id
     * @return 返回学生对象
     */
    @RequestMapping("findById")
    public StudentBean findById(Integer id){
        return service.findById(id);
    }

    /**
     * 按学生id修改学生房间
     * @param id 学生id
     * @param roomId 房间id
     */
    @RequestMapping("updateRoom")
    public String updateRoom(Integer id,Integer roomId){
        service.updateRoom(id,roomId);
        return "ok";
    }

    /**
     * 按id删除学生
     * @param id 学生id
     */
    @RequestMapping("del")
    public String del(Integer id){
        service.del(id);
        return "ok";
    }


    @RequestMapping("add")
    public String add(String studentName, String studentPhone, String sex, String studentImg, Integer classId, Integer roomId){
        StudentBean student = new StudentBean(studentName,studentPhone,sex,studentImg,classId,roomId);
        service.add(student);
        return "ok";
    }
}
